//解析token中带的id
import jwtDecode from "jwt-decode"
import axios from "axios"
//存储登录时候的id,用户名和用户等级
import { useUserStore } from "../../../stores/useUserStore"

export const Token = () => {
  const UserStore = useUserStore()
  function getToken() {
    //解析token
    const token = localStorage.getItem("token")
    const decode = jwtDecode(token)
    const name = decode.scope
    console.log(name,9998)
    axios.get(`http://localhost:3000/ggusers/${name}`).then((res) => {
      UserStore.userId = res.data.result.user_id
      UserStore.userName = res.data.result.user_name
      UserStore.userPassword = res.data.result.user_password
      UserStore.userType = res.data.result.user_type
      UserStore.userOther = res.data.result.user_other
      UserStore.userOnlinestatus = res.data.result.user_onlinestatus
    })
    // console.log(UserStore.userId,9990)
  }
  return { getToken }
}
